package com.jhh.pay.center.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Strings;
import com.jhh.pay.center.model.Order;
import com.jhh.pay.center.model.PayChannel;
import com.jhh.pay.center.search.DocTransformer;
import com.jhh.pay.center.search.mapping.BankInfo;
import com.jhh.pay.center.search.mapping.PayMapping;
import com.jhh.pay.center.service.PayChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author tangxd
 * @Description: TODO
 * @date 2017/12/11
 */
@Component
public class PayOrderMappingTransformer implements DocTransformer<Order,PayMapping> {

    @Override
    public PayMapping transform(Order data) {
        PayMapping mapping = new PayMapping();
        mapping.setAppId(data.getAppId());
        mapping.setOrderNo(data.getOrderNo());
        BankInfo info = new BankInfo();
        info.setBankCard(data.getBankCard());
        info.setBankMobile(data.getBankMobile());
        info.setBankNo(data.getBankNo());
        info.setPersonalName(data.getPersonalName());
        mapping.setBankInfo(info);
        mapping.setChannelId(data.getChannelId());
        if(!Strings.isNullOrEmpty(data.getChannels())) {
            mapping.setChannels((JSONObject)JSON.parse(data.getChannels()));
        }
        mapping.setChannelCustomNo(data.getChannelOrderNo());
        if(!Strings.isNullOrEmpty(data.getExtension())) {
            mapping.setExtension((JSONObject)JSON.parse(data.getExtension()));
        }
        mapping.setMoney(data.getMoney());
        mapping.setNotifyState(data.getNotifyState().code());
        mapping.setOrderState(data.getState().code());
        mapping.setOrderTime(data.getOrderTime());
        mapping.setPostTime(data.getPostTime());
        if(!Strings.isNullOrEmpty(data.getProperties())) {
            mapping.setExtension((JSONObject)JSON.parse(data.getProperties()));
        }
        mapping.setId(data.getId());
        return mapping;
    }
}
